#ifndef __WIZ_SP_NODE_HPP__SHANHAOBO_19800429__
#define __WIZ_SP_NODE_HPP__SHANHAOBO_19800429__

#include "./WizSPForwardDeclare.hpp"

#include "./WizSPBounds.hpp"

namespace Wiz
{
    namespace SP
    {
        namespace Node
        {
            template<class LocationT, typename DataT, class WorldSizeT, class BaseT>
            struct Type : public BaseT
            {
                ////////////////////////////////////
                /// Bounds
                typedef ::Wiz::SP::Bounds::Type
                    <
                    LocationT,
                    WorldSizeT
                    >                                       tBounds;
                WIZ_DECLARE_IO_WITHNAME(tBounds, tBounds)

                ////////////////////////////////////
                /// Location
                typedef LocationT                           tLocation;
                WIZ_DECLARE_IO_WITHNAME(LocationT, tLocation)

                ////////////////////////////////////
                /// Data
                WIZ_DECLARE_CLASS_TYPE(DataT, tData);
                typedef ::Wiz::Map::Type<tData, tBounds>    tDataMap;
                typedef ::Wiz::Array::Type<tData>           tDataArray;
                typedef tDataArray&                         tDataArrayRef;
                typedef tDataArray&                         tDataArrayOut;

                ////////////////////////////////////
                /// WorldSize
                typedef WorldSizeT                          tWorldSize;
                WIZ_DECLARE_IO_WITHNAME(WorldSizeT, tWorldSize)

                ////////////////////////////////////
            public:
                WIZ_INLINE ::Wiz::Bool::Type InsertData(tDataIn InData, tLocationIn InLoc, tWorldSizeIn InRadius)
                {
                    return m_DataMap.InsertUnique(InData, tBounds(InLoc, InRadius));
                }

                ////////////////////////////////////
            public:
                template<class FunctorT>
                ::Wiz::Void::Type ForEachChildren()
                {
                    tDataMap::tForEachIter  FE(m_DataMap);
                    while(FE)
                    {
                        FunctorT(*FE);
                        FE++;
                    }
                }

                template<class FunctorT>
                ::Wiz::Void::Type FindAndErase()
                {
                    m_DataMap::tIterator Curr;
                    m_DataMap::tForEach  FE(Curr, m_DataMap);
                    while(FE.HasMoreElement())
                    {
                        if (FunctorT(*Curr))
                        {
                            FE.Erase();
                        }
                    }
                }
                ///////////////////////////////////
            protected:
                tDataMap                                    m_DataMap;
                ///////////////////////////////////
            };
        } /// end of namespace Node
    } /// end of namespace SP
} /// end of namespace Wiz

#endif /*__WIZ_SP_NODE_HPP__SHANHAOBO_19800429__*/
